package com.huazi.www.frontdesk.servlet;

import com.alibaba.fastjson.JSON;
import com.huazi.www.frontdesk.service.impl.FrontdeskCardServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * 注册
 */
public class FrontdeskCardServlet extends HttpServlet {
    FrontdeskCardServiceImpl frontdeskCardService = new FrontdeskCardServiceImpl();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    @Override
    public void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("text/thml;charse=UTF-8");//修改response域的编码集
        resp.setCharacterEncoding("UTF-8");//修改response域的编码集
        PrintWriter out = resp.getWriter();//创建输出对象
        String idCard = req.getParameter("idCard");//获取传过来的值 idCard
        String pwd = req.getParameter("pwd");//获取传过来的值 pwd
        String name = req.getParameter("name");//获取传过来的值 name
        String sex = req.getParameter("sex");//获取传过来的值 sex
        String age = req.getParameter("age");//获取传过来的值 age
        String phone = req.getParameter("phone");//获取传过来的值 phone
        Integer register = frontdeskCardService.register(pwd, idCard, name, sex, phone, Integer.parseInt(age));//new frontdeskCardService类register方法
        String isregister = JSON.toJSONString(register);//转JSON
        out.println(isregister);//输出到页面
        out.flush();//清空缓存区
        out.close();//关闭缓存区
    }
}
